package com.zhou.project.modules.circle.circleGroupPosts.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.project.components.base.service.BaseService;
import com.zhou.project.modules.circle.circleGroupPosts.dao.CircleGroupPostsDao;
import com.zhou.project.modules.circle.circleGroupPosts.entity.CircleGroupPosts;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@CacheConfig(cacheNames = "posts")
public class CircleGroupPostsService extends BaseService<CircleGroupPostsDao, CircleGroupPosts> {

    @Cacheable(key = "'page:'+#entity.current+':'+#entity.size")
    public Page<CircleGroupPosts> page(CircleGroupPosts entity)
    {
        //分页查询
        Page<CircleGroupPosts> page=Page.of(entity.getCurrent(),entity.getSize());

        //按条件查询
        QueryWrapper<CircleGroupPosts> wrapper=new QueryWrapper<>();
        if (StringUtils.hasLength(entity.getName()))
        {
            wrapper.like("name",entity.getName());
        }
        //调用分页查询
        return baseMapper.selectPage(page,wrapper);
    }

}
